﻿using System;
using System.Collections.Generic;
using GameEditor.View;
using GameEngine.Clients.Silverlight.View.Components;
using PureMVC.Interfaces;
using SilverlightClientEditor.View.Components;

namespace SilverlightClientEditor.View
{
    /*
    public class SilverlightWorldEditorMediator
        : WorldEditorMediator<WorldEditorUC,int>{

        public SilverlightWorldEditorMediator(
            string name,
            //IWorldDataProxy<int> proxy,
            //SilverlightWorldMediator worldMediator,
            //WorldEditorMenuMediator<WorldEditorMenuUC> worldMenuMediator,
            //TileMapEditorMenuMediator<TerrainMenuUC,TerrainMenuUC> tileMapMenuMediator,
            //ItemEditorMediator<ItemEditorUC, ItemUC, MapUC,WorldUC,int, FrameworkElement> itemMediator,
            WorldEditorMenuUC view,
            string outCommand
            )
            : base(name, view, outCommand)
        {
        }

        public new WorldEditorMenuUC ViewComponent
        {
            get { return base.ViewComponent as WorldEditorMenuUC; }
        }

        #region IMediator Members

        /// <summary>
        /// List the <c>INotification</c> names this <c>Mediator</c> is interested in being notified of
        /// </summary>
        /// <returns>The list of <c>INotification</c> names </returns>
        override public IList<string> ListNotificationInterests()
        {
            IList<String> notifications = base.ListNotificationInterests();
            //notifications.Add(SilverlightFacade.FPS_NOTIFICATION);
            //notifications.Add(DesktopMediator.KEY_UP);
            //notifications.Add(DesktopMediator.KEY_DOWN);
            return notifications;
        }

        /// <summary>
        /// Handle <c>INotification</c>s
        /// </summary>
        /// <param name="notification">The <c>INotification</c> instance to handle</param>
        /// <remarks>
        ///     <para>
        ///        Typically this will be handled in a switch statement, with one 'case' entry per <c>INotification</c> the <c>Mediator</c> is interested in. 
        ///     </para>
        /// </remarks>
        override public void HandleNotification(INotification notification)
        {
            //switch (notification.Name)
            //{
            //    case SilverlightFacade.FPS_NOTIFICATION:
            //        ViewComponent.UpdateFPS((int)notification.Body);
            //        break;
                    
            //    case DesktopMediator.KEY_DOWN:
            //        Point newPosition = worldMediator.mapMediator.WorldProxy.Map.CameraPosition;
            //        float newScale = worldMediator.mapMediator.WorldProxy.Map.Scale;
            //        switch (((KeyEventArgs)notification.Body).Key)
            //        {
            //            case Key.Escape:
            //                //menuMediator.TerrainDownButtonPressed = false;
            //                //menuMediator.TerrainUpButtonPressed = false;
            //                //mapMediator.SetMouseCursor(Cursors.Arrow);

            //                break;
            //            case Key.W:
            //                //Move(1, 0, 0, 0);
            //                newPosition.Y++;
            //                worldMediator.mapMediator.WorldProxy.Map.CameraPosition = newPosition;
            //                break;
            //            case Key.S:
            //                //Map.Move(0, 0, 1, 0);
            //                newPosition.Y--;
            //                worldMediator.mapMediator.WorldProxy.Map.CameraPosition = newPosition;
            //                break;
            //            case Key.D:
            //                //Map.Move(0, 1, 0, 0);
            //                newPosition.X++;
            //                worldMediator.mapMediator.WorldProxy.Map.CameraPosition = newPosition;
            //                break;
            //            case Key.A:
            //                //Map.Move(0, 0, 0, 1);
            //                newPosition.X--;
            //                worldMediator.mapMediator.WorldProxy.Map.CameraPosition = newPosition;
            //                break;
            //            case Key.Up:
            //                //Map.SetPosition(Map.Position.X, Map.Position.Y - Map. MapNavigationStep);
            //                //Map.ViewComponent.CreateMap();
            //                break;
            //            case Key.Down:
            //                //Map.SetPosition(Map.Position.X, Map.Position.Y + MapNavigationStep);
            //                //Map.ViewComponent.CreateMap();
            //                break;
            //            case Key.Left:
            //                //Map.SetPosition(Map.Position.X - MapNavigationStep, Map.Position.Y);
            //                //Map.ViewComponent.CreateMap();
            //                break;
            //            case Key.Right:
            //                //Map.SetPosition(Map.Position.X + MapNavigationStep, Map.Position.Y);
            //                //Map.ViewComponent.CreateMap();
            //                break;
            //            case Key.PageDown:
            //                newScale -= 0.1f;
            //                if (newScale <= 0)
            //                    newScale = 0.1f;
            //                worldMediator.mapMediator.WorldProxy.Map.Scale = newScale;
            //                break;
            //            case Key.PageUp:
            //                newScale += 0.1f;
            //                worldMediator.mapMediator.WorldProxy.Map.Scale = newScale;
            //                break;
                       
            //        }
            //        break;
            //}
            base.HandleNotification(notification);
        }

        /// <summary>
        /// Called by the View when the Mediator is registered
        /// </summary>
        override public void OnRegister()
        {
            base.OnRegister();
            //ViewComponent.MenuBar.OnButtonClick += new OnButtonClickHandler(MenuBar_OnButtonClick);
        }

        /// <summary>
        /// Called by the View when the Mediator is removed
        /// </summary>
        override public void OnRemove()
        {
            base.OnRemove();
        }

        #endregion

        //override protected void ViewComponent_OnSizeChanged(Point size)
        //{
        //    worldMediator.mapMediator.SetViewSize(size.X - ViewComponent.MapMenuContainer.ActualWidth - ViewComponent.ItemEditorContainer.ActualWidth,
        //                            size.Y - ViewComponent.MenuBar.ActualHeight);
        //}

        void MenuBar_OnButtonClick(string text)
        {
        //    if (text.Equals(ViewComponent.MenuBar.Exit.Name)) {
        //        MessageBox.Show("TODO");
        //    }
        //    else if (text.Equals(ViewComponent.MenuBar.Save.Name))
        //    {
        //        SaveFileDialog sfd = new SaveFileDialog()
        //        {
        //            Filter = "Map files (*.map)|*.map",
        //            DefaultExt = "*.map"
        //        };
        //        if (sfd.ShowDialog() == true)
        //        {

        //            XDocument doc = worldMediator.mapMediator.WorldProxy.Map.SaveToXML();
        //            System.IO.Stream stream = sfd.OpenFile();
        //            doc.Save(stream);
        //            stream.Close();
        //        }
        //    }
        //    else if (text.Equals(ViewComponent.MenuBar.Load.Name)) {
        //        OpenFileDialog ofd = new OpenFileDialog()
        //        {
        //            Filter = "Map files (*.map)|*.map"
        //        };
        //        if (ofd.ShowDialog() == true)
        //        {
        //            System.IO.StreamReader stream = ofd.File.OpenText();
        //            string map = stream.ReadToEnd();
        //            stream.Close();
        //            XDocument doc = XDocument.Parse(map);
        //            worldMediator.mapMediator.WorldProxy.Map.LoadFromXML(doc);
        //        }
        //    }
        }
    }

     */
}
